package com.fly.caihong.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.webkit.URLUtil;
import android.widget.ImageView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fly.caihong.R;
import com.fly.caihong.activity.FeedbackActivity;
import com.onenine.glide.GlideApp;

import java.io.File;
import java.util.List;

public class ImageAddAdapter extends BaseItemDraggableAdapter<String, BaseViewHolder> {

    private int mImageSize;

    public ImageAddAdapter(@Nullable List<String> data, int imageSize) {
        super(R.layout.layout_photo_item, data);
        mImageSize = imageSize;
    }

    @Override
    protected void convert(BaseViewHolder holder, String path) {
        ImageView imageView = holder.getView(R.id.iv_photo);
        if (FeedbackActivity.IMAGE_ADD.equals(path)) {
            GlideApp.with(mContext).load(R.drawable.ic_add_photo)
                    .override(mImageSize, mImageSize)
                    .centerCrop().into(imageView);
        } else {
            GlideApp.with(mContext).load(URLUtil.isHttpUrl(path) ? path : Uri.fromFile(new File(path)))
                    .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners(20)))
                    .override(mImageSize, mImageSize)
                    .into(imageView);
        }

    }

}
